﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace PaintIsland
{
    public class BlockDef
    {
        public static EnumArray<BlockID, BlockDef> Blocks;
        static BlockDef()
        {
            Blocks = new EnumArray<BlockID, BlockDef>(255);
            Blocks[BlockID.Air] = null;
            Blocks[BlockID.Stone] = new BlockDef(BlockID.Stone, 0);
            Blocks[BlockID.Grass] = new BlockDef(BlockID.Grass, 1, 3, 2);
            Blocks[BlockID.Dirt] = new BlockDef(BlockID.Dirt, 3);
            Blocks[BlockID.Bedrock] = new BlockDef(BlockID.Bedrock, 4);
            Blocks[BlockID.CraftTable] = new BlockDef(BlockID.CraftTable, 5, 8, 7, 7, 6, 7);
        }


        public enum Face: byte
        {
            East,
            West,
            North,
            South,
            Up,
            Down
        }

        private BlockID id;

        public Sprite Icon { get; set; }

        public int topTextureIndex;
        public int bottomTextureIndex;
        public int leftTextureIndex;
        public int rightTextureIndex;
        public int frontTextureIndex;
        public int backTextureIndex;

        public BlockDef(BlockID id, int textureIndex)
            : this(id, textureIndex, textureIndex, textureIndex,textureIndex, textureIndex, textureIndex) { }

        public BlockDef(BlockID id, int verticalTextureIndex, int sideTextureIndex)
            : this(id, verticalTextureIndex, verticalTextureIndex, sideTextureIndex, sideTextureIndex, sideTextureIndex, sideTextureIndex) { }
        public BlockDef(BlockID id, int topTextureIndex, int bottomTextureIndex, int sideTextureIndex)
            : this(id, topTextureIndex, bottomTextureIndex, sideTextureIndex, sideTextureIndex, sideTextureIndex, sideTextureIndex) { }

        public BlockDef(BlockID id, int topTextureIndex, int bottomTextureIndex, int leftTextureIndex, int rightTextureIndex, int frontTextureIndex, int backTextureIndex)
        {
            this.id = id;

            this.topTextureIndex = topTextureIndex;
            this.bottomTextureIndex = bottomTextureIndex;
            this.leftTextureIndex = leftTextureIndex;
            this.rightTextureIndex = rightTextureIndex;
            this.frontTextureIndex = frontTextureIndex;
            this.backTextureIndex = backTextureIndex;
        }
    }
}
